Is it possible to make these functions into one function